package com.wanmait.movie.controller;

import com.wanmait.movie.service.CommonService;
import com.wanmait.movie.util.AjaxResult;
import com.wanmait.movie.util.UploadFileUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping("/common")
public class CommonController {
    @Resource
    private CommonService commonService;
    @Resource
    private UploadFileUtil uploadFileUtil;

    @GetMapping("/clearCache")
    public void clearCache(){
        commonService.clearCache();
    }

    @PostMapping("/uploadPicture")
    public AjaxResult uploadPicture(@RequestParam("file") MultipartFile file) throws IOException {
        String fileUrl = uploadFileUtil.upload(file, "");
        if (fileUrl == null || fileUrl.isEmpty()) {
            return AjaxResult.error("上传失败");
        }
        return AjaxResult.success(fileUrl);
    }
}
